#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n, k; cin >> n >> k;
		vector<int> a(n), b(k);
		for (auto& e : a) cin >> e;
		for (auto& e : b) cin >> e;
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		unsigned long long ans = 0;
		for (int i = n - 1, j = 0; i >= 0; --i)
		{
			if (j < k)
			{
				if (b[j] == 1)
					j++;
				else
				{
					b[j]--;
					ans += a[i];
				}
			}
			else
				ans += a[i];
		}
		cout << ans << endl;
	}
	return 0;
}